package com.zp.io;

import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class ByteArrayOutputstreamTest {
	public static void main(String[] args) throws IOException {
		ByteArrayOutputStream b = new ByteArrayOutputStream();
		String str = "zhangpeng hello!";
		byte[] bt = str.getBytes();
		b.write(bt);
		
		byte[] result = b.toByteArray();
		
		for(int i=0;i<result.length;i++){
			System.out.println((char)result[i]);
		}
		
		//将字节数组输出流转化成文件输出流
		OutputStream os = new FileOutputStream("D:/lisi/zp.txt");
		b.writeTo(os);
	}
}
